/*   1:    */ package org.jetbrains.jps.model.java.impl.compiler;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */ 
/*  17:    */ public class ResourcePatterns
/*  18:    */ {
/*  19: 37 */   private static final Logger a = Logger.getInstance("#org.jetbrains.jps.model.java.impl.compiler.ResourcePatterns");
/*  20: 39 */   private final List<CompiledPattern> b = new ArrayList();
/*  21: 40 */   private final List<CompiledPattern> c = new ArrayList();
/*  22:    */   
/*  23:    */   public ResourcePatterns(JpsJavaCompilerConfiguration paramJpsJavaCompilerConfiguration)
/*  24:    */   {
/*  25: 43 */     List localList = paramJpsJavaCompilerConfiguration.getResourcePatterns();
/*  26: 44 */     for (String str : localList)
/*  27:    */     {
/*  28: 45 */       CompiledPattern localCompiledPattern = a(str);
/*  29: 46 */       if (d(str)) {
/*  30: 47 */         this.c.add(localCompiledPattern);
/*  31:    */       } else {
/*  32: 50 */         this.b.add(localCompiledPattern);
/*  33:    */       }
/*  34:    */     }
/*  35:    */   }
/*  36:    */   
/*  37:    */   public boolean isResourceFile(File paramFile1, @NotNull File paramFile2)
/*  38:    */   {
/*  39: 56 */     if (paramFile2 == null) {
/*  40: 56 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/java/impl/compiler/ResourcePatterns", "isResourceFile" }));
/*  41:    */     }
/*  42: 56 */     String str1 = paramFile1.getName();
/*  43:    */     
/*  44: 58 */     String str3 = paramFile1.getParent();
/*  45:    */     String str2;
/*  46: 59 */     if (str3 != null) {
/*  47: 60 */       str2 = "/" + FileUtilRt.getRelativePath(FileUtilRt.toSystemIndependentName(paramFile2.getAbsolutePath()), FileUtilRt.toSystemIndependentName(str3), '/', SystemInfo.isFileSystemCaseSensitive);
/*  48:    */     } else {
/*  49: 63 */       str2 = null;
/*  50:    */     }
/*  51: 65 */     for (CompiledPattern localCompiledPattern : this.b) {
/*  52: 66 */       if (a(str1, str2, paramFile2, localCompiledPattern)) {
/*  53: 67 */         return true;
/*  54:    */       }
/*  55:    */     }
/*  56: 71 */     if (this.c.isEmpty()) {
/*  57: 72 */       return false;
/*  58:    */     }
/*  59: 76 */     for (int i = 0; i < this.c.size(); i++) {
/*  60: 77 */       if (a(str1, str2, paramFile2, (CompiledPattern)this.c.get(i))) {
/*  61: 78 */         return false;
/*  62:    */       }
/*  63:    */     }
/*  64: 81 */     return true;
/*  65:    */   }
/*  66:    */   
/*  67:    */   private static boolean a(String paramString1, String paramString2, @NotNull File paramFile, CompiledPattern paramCompiledPattern)
/*  68:    */   {
/*  69: 85 */     if (paramFile == null) {
/*  70: 85 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/jps/model/java/impl/compiler/ResourcePatterns", "matches" }));
/*  71:    */     }
/*  72: 85 */     if (!a(paramString1, paramCompiledPattern.fileName)) {
/*  73: 86 */       return false;
/*  74:    */     }
/*  75: 88 */     if (paramString2 != null)
/*  76:    */     {
/*  77: 89 */       if ((paramCompiledPattern.dir != null) && (!a(paramString2, paramCompiledPattern.dir))) {
/*  78: 90 */         return false;
/*  79:    */       }
/*  80: 92 */       if ((paramCompiledPattern.srcRoot != null) && (!a(paramFile.getName(), paramCompiledPattern.srcRoot))) {
/*  81: 93 */         return false;
/*  82:    */       }
/*  83:    */     }
/*  84: 96 */     return true;
/*  85:    */   }
/*  86:    */   
/*  87:    */   private static boolean a(String paramString, Pattern paramPattern)
/*  88:    */   {
/*  89:    */     try
/*  90:    */     {
/*  91:101 */       return paramPattern.matcher(paramString).matches();
/*  92:    */     }
/*  93:    */     catch (Exception localException)
/*  94:    */     {
/*  95:104 */       a.error("Exception matching file name \"" + paramString + "\" against the pattern \"" + paramPattern + "\"", localException);
/*  96:    */     }
/*  97:105 */     return false;
/*  98:    */   }
/*  99:    */   
/* 100:    */   private static CompiledPattern a(String paramString)
/* 101:    */   {
/* 102:110 */     if (d(paramString)) {
/* 103:111 */       paramString = paramString.substring(1);
/* 104:    */     }
/* 105:114 */     paramString = FileUtilRt.toSystemIndependentName(paramString);
/* 106:    */     
/* 107:116 */     String str1 = null;
/* 108:117 */     int i = paramString.indexOf(":");
/* 109:118 */     if (i > 0)
/* 110:    */     {
/* 111:119 */       str1 = paramString.substring(0, i);
/* 112:120 */       paramString = paramString.substring(i + 1);
/* 113:    */     }
/* 114:123 */     String str2 = null;
/* 115:124 */     int j = paramString.lastIndexOf('/');
/* 116:125 */     if (j >= 0)
/* 117:    */     {
/* 118:126 */       str2 = paramString.substring(0, j + 1);
/* 119:127 */       paramString = paramString.substring(j + 1);
/* 120:128 */       if (!str2.startsWith("/")) {
/* 121:129 */         str2 = "/" + str2;
/* 122:    */       }
/* 123:133 */       str2 = c(str2);
/* 124:    */       
/* 125:135 */       str2 = StringUtil.replace(str2, "/.*.*/", "(/.*)?/");
/* 126:136 */       str2 = StringUtil.trimEnd(str2, "/");
/* 127:    */       
/* 128:138 */       str2 = b(str2);
/* 129:    */     }
/* 130:141 */     paramString = c(paramString);
/* 131:142 */     paramString = b(paramString);
/* 132:    */     
/* 133:144 */     Pattern localPattern1 = str2 == null ? null : e(str2);
/* 134:145 */     Pattern localPattern2 = str1 == null ? null : e(b(c(str1)));
/* 135:146 */     return new CompiledPattern(e(paramString), localPattern1, localPattern2);
/* 136:    */   }
/* 137:    */   
/* 138:    */   private static String b(String paramString)
/* 139:    */   {
/* 140:150 */     return paramString.replaceAll("(?:\\.\\*)+", ".*");
/* 141:    */   }
/* 142:    */   
/* 143:    */   private static String c(String paramString)
/* 144:    */   {
/* 145:154 */     paramString = StringUtil.replace(paramString, "\\!", "!");
/* 146:155 */     paramString = StringUtil.replace(paramString, ".", "\\.");
/* 147:156 */     paramString = StringUtil.replace(paramString, "*?", ".+");
/* 148:157 */     paramString = StringUtil.replace(paramString, "?*", ".+");
/* 149:158 */     paramString = StringUtil.replace(paramString, "*", ".*");
/* 150:159 */     paramString = StringUtil.replace(paramString, "?", ".");
/* 151:160 */     return paramString;
/* 152:    */   }
/* 153:    */   
/* 154:    */   private static boolean d(String paramString)
/* 155:    */   {
/* 156:164 */     return (paramString.length() > 1) && (paramString.charAt(0) == '!');
/* 157:    */   }
/* 158:    */   
/* 159:    */   private static Pattern e(@NonNls String paramString)
/* 160:    */   {
/* 161:168 */     return Pattern.compile(paramString, SystemInfo.isFileSystemCaseSensitive ? 0 : 2);
/* 162:    */   }
/* 163:    */   
/* 164:    */   private static class CompiledPattern
/* 165:    */   {
/* 166:    */     @NotNull
/* 167:    */     final Pattern fileName;
/* 168:    */     @Nullable
/* 169:    */     final Pattern dir;
/* 170:    */     @Nullable
/* 171:    */     final Pattern srcRoot;
/* 172:    */     
/* 173:    */     CompiledPattern(@NotNull Pattern paramPattern1, @Nullable Pattern paramPattern2, @Nullable Pattern paramPattern3)
/* 174:    */     {
/* 175:177 */       this.fileName = paramPattern1;
/* 176:178 */       this.dir = paramPattern2;
/* 177:179 */       this.srcRoot = paramPattern3;
/* 178:    */     }
/* 179:    */   }
/* 180:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.java.impl.compiler.ResourcePatterns

 * JD-Core Version:    0.7.0.1

 */